package com.eascs.web.o2o.report.dao;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;

import com.eascs.app.dao.JdbcSession;
import com.eascs.app.runtime.RuntimeSetting;
import com.eascs.web.o2o.report.constants.FefundConstants;

@Repository
public class BaseReportDao {
	@Inject
	JdbcSession jdbcSession;
	@Inject
	JdbcSession jdbcSessionForOracle;
	@Inject
	JdbcSession jdbcSessionForService;
	@Inject
	JdbcSession jdbcSessionForSlaveService;//service从库的数据源配置
	/**
	 * 实体集合
	 */
	public List<Object[]> findObjectsList(String sql){
		return jdbcSession.findObjectsList(sql);
	}
	/**
	 * 执行存储过程
	 */
	public void excuteProReport(String proSql){
		jdbcSession.execute(proSql);
	}
	
	/**
	 * 实体集合-带参数查询
	 */
	public List<Object[]> findObjectsList(String sql,Object... params){
		return jdbcSession.findObjectsList(sql,params);
	}
	
	/**
	 * 插入新数据
	 */
	public void isnertNewBusiness(String insertSql,Object... params){
		jdbcSession.execute(insertSql,params);
	}
	
	/**
	 * 删除数据
	 * @param deleteSql
	 */
	public void deleteNewBusiness(String deleteSql,String param){
		jdbcSession.execute(deleteSql,param);
	}
	
	public List<Object[]> findOracleObjectsList(String sql,Object... params){
		return jdbcSessionForOracle.findObjectsList(sql,params);
	}
	
	
	/**
	 * 实体集合
	 */
	public List<Object[]> findObjectsListForService(String sql,Object... params){
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		if(runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)){
			return jdbcSessionForSlaveService.findObjectsList(sql,params);//只有生产环境有主从隔离（从库只读）
		}
		return jdbcSessionForService.findObjectsList(sql,params);
	}
	
	public void excuteForService(String insertSql,Object... params){
		jdbcSessionForService.execute(insertSql, params);
	}
	
}
